﻿
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using WorkV5APIS.Common;
using WorkV5APIS.Models;
using WorkV5APIS.Models.NoDBModel;

namespace WorkV5APIS.APIS
{
 
    [ApiController]
    [Route("api/[controller]")]
    public class LoginController : Controller
    {

        [Route("LoginUser")]
        public Result LoginUser(S_User user)
        {
            Result result = new Result();
     
            string linkString = AppHelper.ReadAppSettings("Settings", "DB0", "value");

            string dbType = AppHelper.ReadAppSettings("Settings", "DB0", "DbType");
            using (var db = linkDB.CreateDB(linkString, dbType))
                try
                {
                    var userObj = db.Queryable<S_User>().Where(T => T.UserName == user.UserName && T.Password == user.Password).First();

                    if (userObj == null)
                    {

                        throw new Exception("用户名或密码错误！");

                    }
                    result.Code = 200;
                    result.Data = userObj;


                }
                catch (Exception ex)
                {
                    result.Code = 204;
                    result.Msg = ex.Message;


                }

            return result;
        }

    }
}
